#pragma once

#include <QWidget>
#include <QTableView>
#include <QMessageBox>
#include <QFileDialog>
#include <QToolTip>
#include <QHelpEvent>
#include <QHeaderView>

#include <QTextStream>
#include "pagenavigator.h"
#include "remotetablemodel.h"
#include "generaldelegate.h"

class ToolTipTableView : public QTableView
{
    Q_OBJECT
public:
    explicit ToolTipTableView(QWidget *parent = nullptr);

protected:
    bool viewportEvent(QEvent *event) override;
};

class QTablePages : public QWidget
{
    Q_OBJECT
public:
    explicit QTablePages(QWidget *parent = nullptr);
    ~QTablePages();

    void InitTableForm(RemoteTableModel *dataModel, int pageLines = 20);
    void setPageLines(int lines);
    /// @brief 更新分页导航栏
    void updatePageNavigator();
    /// @brief 筛选刷新表格数据
    /// @param dateFrom
    /// @param dateTo
    /// @param content
    void refreshData(const QString &dateFrom = QString(), const QString &dateTo = QString(), const QString &content = QString());
    /// @brief 更新表格数据
    void updateTableView();
    /// @brief 导出表格数据
    /// @param lastcout 去除最后的导出的列数
    void exportToCSV(int lastColumnCount = 1);
    RemoteTableModel *getDataModel();
    QString getFilter();
    // void updatePageUserPermissions(int userId);
signals:
    void deleteRequested(const QModelIndex &index);

public slots:
    void OnPageChanged(int index);
    void onDeleteButtonClicked(const QModelIndex &index);

protected:
    ToolTipTableView *m_tableView;
    RemoteTableModel *m_dataModel;
    PageNavigator *m_pageNavBar;
    int m_pageLines;
    int m_currentPage;
    int m_totalPages;
    QString m_filter;
};